package com.ltedu.oss.service.impl;

import com.ltedu.oss.service.VideoService;
import com.ltedu.oss.utils.FileKit;
import com.ltedu.oss.utils.UploadVideoUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @className: VideoServiceImpl
 * @auther: Jerry
 * @date: 2020/12/10 16:22
 * @desctiption: TODO
 * @version: 1.0
 */
@Service
public class VideoServiceImpl implements VideoService {

    /**
     * 上传视频
     *
     * @param file 文件
     * @return {@link String}
     */
    @Override
    public String uploadVideo(MultipartFile file) {
        try {
            InputStream inputStream = file.getInputStream();
            String originalFilename = file.getOriginalFilename();
            String title = FileKit.getFilename(originalFilename);
            return UploadVideoUtils.uploadVideo(title, originalFilename, inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
